package com.wanmait.computershop.webController;

import com.wanmait.computershop.dao.ProductDAO;
import com.wanmait.computershop.vo.BuyNow;
import com.wanmait.computershop.vo.Product;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("web")
public class WebProductController {

    @GetMapping("product")
    public String product(Integer pid, Model model)
    {
        model.addAttribute("productDetil", ProductDAO.selectById(pid));
        return "web/product";
    }

    @GetMapping("buyNow")
    public String buyNow(Integer id,Integer addNum,Model model)
    {
        Product product = ProductDAO.selectById(id);
        BuyNow buyNow = new BuyNow();
        buyNow.setImage(product.getImage());
        buyNow.setPrice(product.getPrice());
        buyNow.setTitle(product.getTitle());
        buyNow.setBuyNum(addNum);
        model.addAttribute("buyNow",buyNow);
        System.out.println(buyNow.getTitle());
        return "web/buynow";
    }
}
